/*
 * @Author: 四川华西绿舍建材有限公司
 * @Date: 2023-12-08 10:17:08
 * @LastEditors: 陈波
 * @LastEditTime: 2024-02-28 21:39:23
 * @Description: 
 * @FilePath: \graDesign\src\store\forgetPwd.ts
 */
import { defineStore } from "pinia";

type wayType = 'mb_verify' | 'face_verify';

const useForgetPwd: any = defineStore("forgetPwd", {
  state: () => {
    return {
      // 账户核实类型
      verifyType: '',
      // 用户名
      username: '',
      // 手机号
      phone: '',
      // 存储用户信息
      userInfo: {},
      // 验证方式(密保 or 人脸) 默认密保
      verifyWay: 'mb_verify' as wayType,
      // 验证码
      // verifyCode: '',
      // 新密码
      newPwd: '',
      // 确认密码
      confirmPwd: '',
      // 人脸验证是否通过
      isVerifySuccess: false,
    }
  },
  actions: {
    // 设置账户数据
    setAccountData(model: any) {
      this.verifyType = model.verifyType;
      this.username = model.username;
      this.phone = model.phone;
    },
    // 设置验证方式
    setVerifyWay(param: any) {
      this.verifyWay = param;
      // console.log('param', param)
    },
    // 根据用户名和手机号请求接口获取信息
    setAccountInfo(info: any) {
      this.userInfo = info;
    },
    // 设置验证码
    // setVerifyCode(param: any) {
    //   this.verifyCode = param;
    // },
    // 设置密保问题答案
    setAnswer(type: string, answer: string) {
      switch (type) {
        case 'securityA1':
          this.userInfo.securityA1 = answer;
          break;
        case 'securityA2':
          this.userInfo.securityA2 = answer;
          break;
        case 'securityA3':
          this.userInfo.securityA3 = answer;
          break;
      }
      // 判断所有答案都已填写时
      if (this.userInfo.securityA1 && this.userInfo.securityA2 && this.userInfo.securityA3) {
        this.isVerifySuccess = true;
      } else {
        this.isVerifySuccess = false;
      }
    },
    // 设置新密码
    setNewPwd(newPwd: any, confirmPwd: any) {
      this.newPwd = newPwd;
      this.confirmPwd = confirmPwd;
    },
    // 设置是否通过人脸验证
    setVerifySuccess(flag: boolean) {
      this.isVerifySuccess = flag;
    },
  }
});

export default useForgetPwd;
